/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ing.sisval.gui.control.model;

import java.util.List;
import org.ing.sisval.be.BELado;

import org.rx.cr.gui.table.AbstractTableModel;

/**
 *
 * @author Mysham
 */
public class ModeloLado extends AbstractTableModel<BELado> {

    private final List<BELado> List;

    public ModeloLado() {
        setTitles(new String[]{"Lado", "Medida", "Val. Unit."});
        this.List = null;
    }

    public ModeloLado(List<BELado> List) {
        setTitles(new String[]{"Lado", "Medida", "Val. Unit."});
        this.List = List;

    }

    @Override
    public Object getObjectCell(int fila, int columna) {
        switch (columna) {
            case 0:
                return get(fila).getNombre();

            case 1:
                return get(fila).getMedida();
            case 2:
                return get(fila).getValorunitario();
            default:
                return null;
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int colIndex) {
        return true;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        BELado be = List.get(rowIndex);
        if (0 == columnIndex) {
            be.setNombre((String) aValue);
        } else if (1 == columnIndex) {
            be.setMedida(Double.parseDouble(aValue.toString()));
        } else if (2 == columnIndex) {
            be.setValorunitario(Double.parseDouble(aValue.toString()));
        }

    }


    @Override
    public int getColumnCount() {
        return 3;
    }

}
